Ext.define('Xyh.controller.Currency', {
			extend : 'Ext.app.Controller',
			models : ['Currency'],
			stores : ['Currency'],
			views : ['currency.List','currency.Add','currency.Edit'],

			init : function() {
				this.control({
							'currency button[action=addCurrency]' : {
								click : this.showAddCurrency
							},
							'currencyadd button[action=save]' : {
								click : this.addCurrency
							},
							'currency gridpanel' : {
								itemdblclick : this.showUpdateWindow
							},
							'currencyedit button[action=save]' : {
								click : this.updateCurrency
							}
						});

			},
			showAddCurrency : function(button) {
				Ext.widget('currencyadd');
			},
			addCurrency : function(button) {
				var win = button.up('window');
				var form = win.down('form').getForm();
				if (form.isValid()) {
					form.submit({
								success : function(form, action) {
									Ext.Msg.alert('OK', '添加成功');
									win.close();
									Ext.getStore('Currency').load();

								},
								failure : function(form, action) {
									Ext.Msg.alert('ERROR', '添加失败');
								}
							});
				}
			},
			showUpdateWindow : function(grid, record) {
				var edit = Ext.createWidget('currencyedit');
				edit.down('form').loadRecord(record);

			},
			updateCurrency : function(button) {
				var win = button.up('window');
				var form = win.down('form').getForm();
				if (form.isValid()) {
					form.submit({
								success : function(form, action) {
									Ext.Msg.alert('OK', '修改成功');
									win.close();
									Ext.getStore('Currency').load();
								},
								failure : function(form, action) {
									Ext.Msg.alert('ERROR', '修改失败');
								}
							});
				}
			}

		});